class Solution(object):
    def maxCoins(self, piles):
        piles.sort()
        n = len(piles)
        left = 0
        right = n - 1
        ans = 0
        while left < right:
            ans += piles[right - 1]
            left += 1
            right -= 2
        return ans